package com.lambert.young.im.command;

import com.alibaba.fastjson2.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author beiming
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    private String name;

    private LocalDateTime time;

    private String message;

    private Integer code;

    public static TextWebSocketFrame fail(String message){
        return new TextWebSocketFrame(JSON.toJSONString(new Result("系统消息", LocalDateTime.now(),message,ResultType.BASIC_ERROR.getCode())));
    }

    public static TextWebSocketFrame success(ResultType code){
        return new TextWebSocketFrame(JSON.toJSONString(new Result("系统消息", LocalDateTime.now(),code.getMessage(),code.getCode())));
    }

    public static TextWebSocketFrame success(ResultType code,String message){
        return new TextWebSocketFrame(JSON.toJSONString(new Result("系统消息", LocalDateTime.now(),message,code.getCode())));
    }

    public static TextWebSocketFrame success(String user,String message){
        return new TextWebSocketFrame(JSON.toJSONString(new Result(user, LocalDateTime.now(),message,ResultType.CHAT_MESSAGE.getCode())));
    }
}
